I'm having hard times with forwading the logic between controllers. I have a ControllerBase.php
with the following logic:
use Phalcon\Mvc\Controller;
class ControllerBase extends Controller {
protected function forward ($uri) {
$uriParts = explode("/", $uri);
$params = array_slice($uriParts, 2);
return $this->dispatcher->forward(
array(
"controller" => $uriParts[0],
"action" => $uriParts[1],
"params" => $params
)
);
}
}
and the UrlController.php
that extends the ControllerBase
with the following logic:
class UrlController extends ControllerBase {
public function processRequestAction () {
$this->view->disable();
$request = new \Phalcon\Http\Request();
if (!$request->isPost()) {
$this->forward("errors/notfound");
}
}
}
The code is pretty straightforward. Whenever the request is not a POST request the code should redirect the logic to the ErrorsControllers with this logic:
class ErrorsController extends ControllerBase {
public function notfound () {
$response = new \Phalcon\Http\Response();
$data = array(
"success" => "false",
"message" => "404 Not Found"
);
$response->setHeader("Content-Type", "application/json");
$response->setStatusCode(404, "Not Found");
$response->setContent(json_encode($data));
return $response;
}
}
Whenever I call $this->forward
the method from ControllerBase is executed just fine but the $this->dispatcher->forward
method is not executed at all. I took this example from invo application available on GitHub. Am I missing something here? Do I need to register any custom functions in the boostrap index.php
file?